package com.projet.glb2r.Affiche;

import android.app.Activity;
import android.content.Intent;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.provider.BaseColumns;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;

import com.projet.glb2r.R;
import com.projet.glb2r.Activite.ActiviteCreationFacture;
import com.projet.glb2r.Base_et_Provider.TableClient;
import com.projet.glb2r.DAO.DAOClient;
import com.projet.glb2r.Objet.ObjetClient;

public class ShowClient extends Activity implements OnClickListener{
	
	private Button valider ;
	private ObjetClient client = new ObjetClient();
	private DAOClient clientDAO = new DAOClient();
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.word);
		valider = (Button) findViewById(R.id.bbvalider);
		
		Uri uri = getIntent().getData();
		Cursor cursor = managedQuery(uri, null, null, null, null);

		if (cursor == null) {
			finish();
		} else {
			cursor.moveToFirst();

			TextView word = (TextView) findViewById(R.id.word);
			TextView definition = (TextView) findViewById(R.id.definition);
			

			int wIndex = cursor.getColumnIndexOrThrow(TableClient.KEY_NOMCLIENT);
			int dIndex = cursor.getColumnIndexOrThrow(TableClient.KEY_PRENOMCLIENT);
			int cIndex = cursor.getColumnIndexOrThrow(BaseColumns._ID);
			
			client.setID(cursor.getInt(cIndex));
			
			ActiviteCreationFacture.objetclient = clientDAO.getClient(getContentResolver(), "rowid =?", new String[]{""+client.getID()});;
			
			
			word.setText(cursor.getString(wIndex));
			definition.setText(cursor.getString(dIndex));
			
			valider.setOnClickListener(new OnClickListener() {
				
				public void onClick(View v) {
					// TODO Auto-generated method stub
					Intent intention = new Intent ("android.intent.action.ActiviteCreationFacture");
					startActivity(intention);
				}
			});
			
			
		}
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		MenuInflater inflater = getMenuInflater();
		inflater.inflate(R.menu.options_menu, menu);
		return true;
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		switch (item.getItemId()) {
		case R.id.search:
			onSearchRequested();
			return true;
		default:
			return false;
		}
	}

	public void onClick(View arg0) {
		// TODO Auto-generated method stub
		
	}
}
